﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ViewROI
{
    public class HMisc
    {
        public static double DistancePp(double y1, double x1, double y2, double x2)
        {
            double dis2 = Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2);
            return Math.Sqrt(dis2);
        }

        public static double AngleLl(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
        {
            double cosfi = 0, fi = 0, norm = 0;

            double dsx = x2 - x1;
            double dsy = y2 - y1;

            double dex = x4 - x3;
            double dey = y4 - y3;

            cosfi = dsx * dex + dsy * dey;
            norm = (dsx * dsx + dsy * dsy) * (dex * dex + dey * dey);
            cosfi /= Math.Sqrt(norm);

            if (cosfi >= 1.0) return 0;
            if (cosfi <= -1.0) return Math.PI;
            fi = Math.Acos(cosfi);

            if (180 * fi / Math.PI < 180)
            {
                return 180 * fi / Math.PI;
            }
            else
            {
                return 360 - 180 * fi / Math.PI;
            }
        }
    }
}
